package com.example.page;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;

public abstract class AnyPage extends Page{
    @FindBy(css = "a[href=\"./?lang=en_US\"]")
    public WebElement englishLink;

    @FindBy(css = "a[href=\"./?lang=nl_NL\"]")
    public WebElement nederlandsLink;

    @FindBy(css = "div[class=\"languages\"]")
    public WebElement languagesPanel;

    public void setEnglishLanguage(){
        englishLink.click();
    }

     public void setNederlandsLanguage(){
         nederlandsLink.click();
    }

    public String getLanguage()
    {
        List<WebElement> elements;
        elements = languagesPanel.findElements(By.xpath("ul/li"));
        for (int i = 0; i< elements.size(); i++)
        {
            if (elements.get(i).getAttribute("class").equals("selected"))
                return elements.get(i).findElement(By.xpath("a")).getText();
        }
        return null;
    }
}
